package com.hycat.mail.order.controller;

import java.util.Arrays;
import java.util.Map;

import com.hycat.mail.order.client.ProductClient;
import com.hycat.mail.order.vo.OrderSubmitVo;
import com.hycat.mail.order.vo.OrderVo;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.hycat.mail.order.entity.OrderEntity;
import com.hycat.mail.order.service.OrderService;
import com.hycat.mail.common.utils.PageUtil;
import com.hycat.mail.common.utils.R;
import javax.servlet.http.HttpServletRequest;


/**
 * 订单
 *
 * @author lzhycat
 * @email 2680628835@qq.com
 * @date 2022-07-16 20:28:20
 */
@Slf4j
@RestController
@RequestMapping("/order/order")
public class OrderController {
    private final static Logger logger = LoggerFactory.getLogger(OrderController.class);

    @Autowired
    private OrderService orderService;


    @GetMapping("/orderView")
    public R orderView() {
        OrderVo orderVo = orderService.orderView();
        return R.ok().setData(orderVo);
    }

    @PostMapping("/orderPay")
    public R orderPay(OrderSubmitVo vo) {
        OrderEntity orderEntity = orderService.orderPay(vo);
        return R.ok("订单支付成功").setData(orderEntity);
    }

    @GetMapping("/getByOrderSn")
    public OrderEntity getByOrderSn(@RequestParam("OrderSn") String orderSn) {
        OrderEntity entity = orderService.getByOrderSn(orderSn);
        return entity;
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtil page = orderService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("order:order:info")
    public R info(@PathVariable("id") Long id){
		OrderEntity order = orderService.getById(id);

        return R.ok().put("order", order);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("order:order:save")
    public R save(@RequestBody OrderEntity order){
		orderService.save(order);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("order:order:update")
    public R update(@RequestBody OrderEntity order){
		orderService.updateById(order);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("order:order:delete")
    public R delete(@RequestBody Long[] ids){
		orderService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
